<template>
    <!-- 组件的模板 -->
    <div class="page attendance-set show-footerBtn" :style="isIphoneX?'padding-bottom: 95px;':''">
        <div class="weui-cells">
            <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">考勤名称</label></div>
                <div class="weui-cell__bd">
                    <input class="weui-input" type="text" v-model="taskObj.name" :value="taskObj.name" placeholder="请输入" maxLength="20">
                </div>
            </div>
        </div>
        <div class="weui-cells">
            <a class="weui-cell_access block" href="javascript:;"  @click="addGroup">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <p>考勤小组<span class="tip">(新增人员自动加入)</span></p>
                    </div>
                    <div class="weui-cell__ft" v-if="taskObj.participant_group.length">{{taskObj.participant_group.length}}个小组</div>
                    <div class="weui-cell__ft" v-else></div>
                </div>
                <div class="add-team">
                    <template v-if="taskObj.participant_group_name.length">
                        <span class="team" v-for="item in taskObj.participant_group_name">{{item}}</span>
                    </template>
                    <span class="button"></span>
                </div>
            </a>
            <a class="weui-cell weui-cell_access" href="javascript:;" @click="addMember">
                <div class="weui-cell__bd">
                    <p>其他考勤人员</p>
                </div>
                <div class="weui-cell__ft" v-if="taskObj.participant_user.length">{{taskObj.participant_user.length}}<template v-if="taskObj.participant_user.length">人</template></div>   
                <div class="weui-cell__ft" v-else> </div>                
            </a>
        </div>            
       
        <div class="weui-cells option-set">
           
            <div class="weui-cell">
                <div class="weui-cell__bd">
                    <p>排班方式</p>
                </div>
                <div class="weui-cell__ft">{{taskObj.work_type_info}}</div>
            </div>
            <a class="weui-cell weui-cell_access" href="javascript:;" v-if="taskObj.work_type_info != '弹性时间' && taskObj.work_type_info != '固定时间'"@click="classesSet">
                <div class="weui-cell__bd">
                    <p>班次设置</p>
                </div>
                <div class="weui-cell__ft" v-if="taskObj.schedule_list.length != 0">共有{{taskObj.schedule_list.length}}个班次</div>
                <div class="weui-cell__ft" v-else></div>
            </a>  
            <a class="weui-cell weui-cell_access" href="javascript:;" v-if="taskObj.work_type_info == '弹性时间' || taskObj.work_type_info == '固定时间'" @click="selectKqTime">
                <div class="weui-cell__bd">
                    <p>考勤时间</p>
                </div>
                <div class="weui-cell__ft placeholder" v-if="taskObj.work_type_info == '固定时间'">
                    <span v-for="item in taskObj.work_time_range">{{item.start.time}}-<span v-if="item.cross == 1">次日</span>{{item.end.time}}</span>
                </div>
                <div class="weui-cell__ft" v-if="taskObj.work_type_info == '弹性时间'">{{taskObj.work_time_length}}</div>
            </a>
            <a class="weui-cell weui-cell_access" href="javascript:;" v-if="taskObj.work_type_info == '弹性时间'" @click="selectBeginTime">
                <div class="weui-cell__bd">
                    <p>开始时间</p>
                </div>
                <div class="weui-cell__ft">{{today_begin}}</div>
            </a>
            <a class="weui-cell weui-cell_access" href="javascript:;" @click="selectDate" v-if="taskObj.work_type_info == '固定时间' || taskObj.work_type_info == '弹性时间'">
                <div class="weui-cell__bd">
                    <p>考勤日期</p>
                </div>
                 <!--修改时返回的数据；如为修改b==true或者w == true 否则是请求接口的数据-->
                <template v-if="taskObj.work_date_type == 0">
                    <div class="weui-cell__ft" v-if="b == true && backTime.length">
                        <span v-for="bItem in backTime">{{bItem}}</span>
                    </div>
                    <div class="weui-cell__ft" v-if="b == false && taskObj.work_date.length">
                        <span v-for="item in taskObj.work_date">{{item}}</span>
                    </div>
                </template>
                <template v-if="taskObj.work_date_type == 1">
                    <div class="weui-cell__ft" v-if="w == true && backweek">{{backweek.start_date}}&nbsp;&nbsp;{{backweek.end_date}}</div> 
                    <div class="weui-cell__ft" v-if="w == false && taskObj.work_week">{{taskObj.work_week.start_date}}&nbsp;&nbsp;{{taskObj.work_week.end_date}}</div> 
                </template>
            </a>
        </div>  
        <div class="weui-cells option-set">
            <a class="weui-cell weui-cell_access" href="javascript:;" @click="addPosition">
                <div class="weui-cell__bd">
                    <p>考勤地点</p>
                </div>
                <div class="weui-cell__ft" v-if="taskObj.position.length != 0">共{{taskObj.position.length}}个</div>
                <div class="weui-cell__ft" v-else></div>
            </a>                             
        </div>
        <div class="weui-cells__tip">不在附近打卡记为异常，非必填</div>        

        <div class="weui-cells option-set">
            <a class="weui-cell weui-cell_access" href="javascript:;" @click="selectField">
                <div class="weui-cell__bd">
                    <p>考勤填写项</p>
                </div>
                <div class="weui-cell__ft">{{require_word}}</div>
            </a> 
        </div>
        <div class="weui-cells__tip">可设置用户打卡时需要填写的内容</div>         
        <div class="weui-cells option-set">
            <a class="weui-cell weui-cell_access" href="javascript:;" @click="selectNoticeType">
                <div class="weui-cell__bd">
                    <p>考勤通知</p>
                </div>
                <div class="weui-cell__ft">{{noticeMessage}}</div>
            </a>
        </div>
        
        <div class="btn-box bg-color fixed" :style="isIphoneX?'padding-bottom: 35px;':''" @click="editSubmit(2)" v-if="taskObj.work_type_info == '人员排班'"><a href="javascript:;" class="weui-btn weui-btn_primary">保存并开始排班</a></div>
        <div class="btn-box bg-color fixed" :style="isIphoneX?'padding-bottom: 35px;':''" @click="editSubmit(1)" v-else><a href="javascript:;" class="weui-btn weui-btn_primary">保存</a></div>
    </div>
</template>

<script>
    let pageDate = {}
    let taskId = ''

    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */
    
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */
    import * as util from 'js/util.js'
    import cache from 'gapi/cache.js'
    import commonPage from 'clientApi/commonPage.js'
    import widget from 'gapi/widget'
    import clientUi from 'gapi/clientUi.js'
    
    /**
     *  组件实例对象
     */
    export default {
        components: {

        },
        data: function(){
            return{
                dataChane:false,  //判断数据是否有变化
                b:false,
                backTime:[],
                w:false,
                backweek:[],
                position_tune1: 0,//是否允许地点微调 0：不允许 1：允许，不传或空表示不允许
                taskObj:{
                    name:'', // 考勤名称
                    participant_group:'',//考勤小组
                    participant_group_name:'',  //考勤小组名称
                    participant_user:'',  // 考勤其他人员
                    position:[],   // 考勤位置
                    require_field_formid:'',
                    // require_field:{photo:0,position:1,remark:0},//考勤必填项 0:选中／1:不选中 
                    require_field:[],
                    notice_type:0,   // 考勤通知
                    work_type:'',  //排班方式
                    work_time_range:[],   // 考勤时间
                    work_time_length:'',
                    work_date_type: 1,
                    work_date:'',
                    work_week:'',
                    adjust_distance:'',//地点微调范围默认200
                    examples_img_url:[],
                    example_img_thumb_url:[],
                    schedule_list: [],//班次设置               
                    
                },
                positionParam: [],//传回去的考勤地点参数
                checkparticapant: 1,
                today_begin:'00:00',//弹性考勤开始时间
                today_begin_min:'',//弹性考勤开始时间（分钟）

            }
        },
        computed: {
            noticeMessage(){
                if(this.taskObj.notice_type==0){
                    return '提交不需要通知'
                }else if(this.taskObj.notice_type==1){
                    return '仅考勤状态异常时通知'
                }else if(this.taskObj.notice_type==2){
                    return '提交考勤即通知'
                }
            },
            requireFieldMessage(){
                let res = ''
                if(this.taskObj.require_field.photo==1){
                    res = '拍照'
                }
                if(this.taskObj.require_field.position==1){
                    res = res?res+'、位置':'位置'
                }
                if(this.taskObj.require_field.remark==1){
                    res = res?res+'、备注':'备注'
                }
                return res
            },
            require_word() {
                let str = ''
                this.taskObj.require_field.forEach((obj) => {
                    str += `、${obj.info.title}`
                })
                return str.substr(1)
            },
            isIphoneX: function(){
                return util.isIphoneX()
            }
        },
        vuex: {
            getters: {

            },
            actions: {

            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                cache.getCache('KqCacheMessge',(data)=>{
                    if(data){
                        pageDate.project_id = data.project_id || util.getUrddataString('project_id')
                        pageDate.team_id = data.team_id || util.getUrddataString('team_id')
                    }else{
                        pageDate.project_id = util.getUrddataString('project_id')
                        pageDate.team_id = util.getUrddataString('team_id')
                    }
                    taskId = util.getUrddataString('task_id')
                    if(taskId&&taskId!='undefined'){
                        this.getDate()
                    }else{
                        cache.deleteCache('getDate')
                    }
                 })

            },
            //添加参与小组
            addGroup(){
                cache.setMemoryCache('participantGroup', this.taskObj.participant_group)
                window.location.href="dmsaas://KaoqinAddGroup"
            },
            //添加办公地点
            addPosition(){
                cache.deleteCache('KaoqinAddPosition')
                let positionId = new Array
                this.taskObj.position.forEach((obj) => {
                    if(obj.id){
                        positionId.push(parseInt(obj.id))
                    }else{
                        positionId.push(obj)
                    }
                })
                cache.setCache('KaoqinAddPosition',positionId,60*60*24) 
                // cache.setMemoryCache('KaoqinAddPosition',{key:'KaoqinAddPosition', value:positionId})
                window.location.href="dmsaas://KaoqinAddPosition"
            },
            //添加参与人员
            addMember(){
                cache.setMemoryCache('participantMember', this.taskObj.participant_user)
                let encodeStr = encodeURIComponent(`origin_type=kaoqin`)
                location.href = `dmsaas://KaoqinAddMember?urdData=${encodeStr}`
            },
            //删除办公地点
            deletePosition(index){
                for(var i = 0 ;i< this.taskObj.position.length;i++){
                    if(i>=index){
                        this.taskObj.position[i] = this.taskObj.position[i+1]
                    }
                }
                this.taskObj.position.pop()
            },
            //考勤必填项
            selectField(){
                // let imageObj = {
                //     require_field : this.taskObj.require_field, 
                //     img_url : this.taskObj.examples_img_url,  // 原图
                //     img_thumb_url : this.taskObj.example_img_thumb_url  // 缩略图
                // }
                // console.log(imageObj)
                // cache.setMemoryCache('requireField', imageObj)
                // window.location.href="dmsaas://KaoqinSetRequirefield"
                cache.setCache('designInfo', this.taskObj.require_field, 10000)
                location.href = `dmsaas://SetupRequire`
            },
            selectNoticeType(){
                cache.setMemoryCache('noticeType', {key:this.taskObj.notice_type})
                window.location.href="dmsaas://KaoqinSetNoticetype"
            },
            // 考勤时间
            selectKqTime (){
                if(this.taskObj.work_type_info == '固定时间'){
                    cache.setMemoryCache('workTimeRange', this.taskObj.work_time_range)
                    window.location.href = "dmsaas://KaoqinFixedTime?urdData="+encodeURIComponent(`isdisabled=${555}`)
                }else if(this.taskObj.work_type_info == '弹性时间'){
                    this.selectWorkTime()
                }
            },
            // 弹性时间 -- 时间选择
            selectWorkTime(){
                let data = {
                    data1: []
                }
                let select = ['0']
                for(let i = 1 ; i<24.5 ; i+=0.5){
                    data.data1.push(i)
                }
                if(this.taskObj.work_time_length){
                    select[0]=data.data1.indexOf(Number(this.taskObj.work_time_length))+''
                }
                clientUi.showPicker(data, select, '工作时间(小时)', (returnData) => {
                    if(returnData.data1){
                        this.taskObj.work_time_length = data.data1[returnData.data1]
                    }else{
                        this.taskObj.work_time_length = this.taskObj.work_time_length
                    }
                    
                })
            },
            // 地点微调
            changeTuneDistance(){
                let tune_distances = {
                    data1: ['关闭',100,200,500,1000],
                }
                let index = tune_distances.data1.indexOf(Number(this.taskObj.adjust_distance))
                
                let select = [index]
                clientUi.showPicker(tune_distances, select, "请选择微调范围", (data) => {
                    // console.log(data)
                    if(data&&data.data1){
                       this.taskObj.adjust_distance = tune_distances.data1[data.data1]
                       // console.log(this.taskObj.adjust_distance) 
                    }
                })
            },
            //考勤日期
            selectDate (){
                if(this.taskObj.work_date_type == 0){ //按天设置
                    if(this.b == true){
                        cache.setMemoryCache('workDate', this.backTime)
                    }else{
                        cache.setMemoryCache('workDate', this.taskObj.work_date)
                    }
                    window.location.href="dmsaas://KaoqinEditWorkTime"

                }else if(this.taskObj.work_date_type == 1){ // 按周设置
                    if(this.w == true){
                        cache.setMemoryCache('workWeek', this.backweek)
                    }else{
                        cache.setMemoryCache('workWeek', this.taskObj.work_week)
                    }
                    window.location.href="dmsaas://KaoqinEditWorkDate"
                }
            },
            editSubmit (type_num){
                if(!this.checkDate()){
                    return
                }
                let that = this
                let getSubmitDate = this.getSubmitDate()
                let message = '修改考勤规则当日生效，当日将按照新的规则执行，是否确定修改'
                clientUi.showDialog('提醒', message, function(data){
                    if(data.status == 1){
                        that.postAjax(getSubmitDate,type_num)
                        // cache.deleteCache('KaoqinClassesSet')
                        // cache.deleteCache('KaoqinAddPosition')                            
                        // cache.getMemoryCache('editKqViewID', (data) => {
                        //     if(data){
                        //         if(type_num == 2){
                        //             window.location.href="dmsaas://KaoqinScheduleEdit?"+`task_id=${taskId}&type=`+'set'
                        //         }else{                                        
                        //             // widget.toast('修改成功')
                        //             commonPage.goBack(1, {'key':'yy_kqtaskset'}, data.editKqViewID)
                        //         }
                        //     }
                        // })
                    }
                })
            },
            postAjax (getSubmitDate,type_num){
                // let getSubmitDate = this.getSubmitDate()
                util.ajax({
                    url: '/attendance/attendance_task/update',
                    type:'POST',
                    data: getSubmitDate,
                    success: (res) => {
                        console.log(JSON.stringify(res)) 
                        if(res&&res.errno==0){     
                            // this.editSubmit (type_num) 
                            cache.deleteCache('KaoqinClassesSet')
                            cache.deleteCache('KaoqinAddPosition')                            
                            cache.getMemoryCache('editKqViewID', (data) => {
                                if(data){
                                    if(type_num == 2){
                                        window.location.href="dmsaas://KaoqinScheduleEdit?"+`task_id=${taskId}&type=`+'set'
                                    }else{                                        
                                        // widget.toast('修改成功')
                                        commonPage.goBack(1, {'key':'yy_kqtaskset'}, data.editKqViewID)
                                    }
                                }
                            })
                        }else if(res.errno==21039){
                            clientUi.showDialog('提醒', '考勤小组、人员与其他考勤规则冲突，确定将其拉至该考勤规则', (status) => {
                                if(status.status == 1){
                                   this.checkparticapant = 0
                                   let getSubmitDate = this.getSubmitDate()
                                   this.postAjax (getSubmitDate,type_num)
                                }
                            }, '确认', '取消')
                        }else if(res.errmsg){
                             widget.toast(res.errmsg)
                        }else{
                            widget.toast('提交失败')
                        }
                    },
                    error: (xhr, status) => {
                        widget.toast('服务器异常')
                    },
                    noNetwork: () => {
                        widget.toast('网络连接失败，请检查网络')
                    }
                })
            },
            getSubmitDate(){
                if(this.taskObj.work_type_info == '固定时间'){
                    this.taskObj.work_type = 0
                }else if(this.taskObj.work_type_info == '弹性时间'){
                    this.taskObj.work_type = 1
                }else if(this.taskObj.work_type_info == '人员排班'){
                    this.taskObj.work_type = 2
                }
                let positionInfo = new Array;

                if(this.taskObj.position.length != 0){                    
                    if(this.taskObj.position[0].id){

                        this.taskObj.position.forEach((obj) => {
                            // if(obj.id){
                                this.positionParam.push(parseInt(obj.id) )
                            // }
                        })
                        positionInfo = this.positionParam
                    }else{
                        positionInfo = this.taskObj.position
                    }
                }else{
                    positionInfo = this.taskObj.position
                }
                let data = {
                    team_id:pageDate.team_id,
                    project_id: pageDate.project_id,
                    task_id: taskId,
                    name: this.taskObj.name,  // 考勤名称
                    participant_group: this.taskObj.participant_group, // 考勤小组
                    participant_user: this.taskObj.participant_user,  // 考勤人员
                    position: positionInfo,  // 考勤位置
                    work_type: this.taskObj.work_type , //排班方式
                    work_time_range: this.taskObj.work_time_range,  // 固定时间
                    work_time_length: this.taskObj.work_time_length,  // 弹性时间
                    work_date_type: this.taskObj.work_date_type,   // 考勤日期方式
                    work_date: this.b == true ? this.backTime : this.taskObj.work_date,   // 按天设置 
                    work_week: this.w == true ? this.backweek : this.taskObj.work_week,   //按周设置
                    require_field_formid: this.taskObj.require_field_formid,   //考勤必填项必填项id
                    require_field: this.taskObj.require_field, // 考勤必填项
                    notice_type: this.taskObj.notice_type,  // 考勤通知
                    schedule_list: this.taskObj.schedule_list,
                    checkparticapant: this.checkparticapant,
                    today_begin: this.today_begin_min
                }
                return data
            },
            // 更新数据
            updateDate(data){
                // console.log(data)
                if(data){
                    let key = data.key
                    let value = data.value
                    switch(key){ 
                            //更新考勤位置信息
                        case 'position':
                            this.taskObj.position.push(value)
                            break
                        case 'participantGroup':
                            //更新参与小组信息
                            console.log("更新参与小组信息"+JSON.stringify(data))
                            this.taskObj.participant_group = value
                            this.taskObj.participant_group_name = data.name
                            break
                        case 'participantMember':
                            //更新参与人员信息
                            this.taskObj.participant_user = value
                            break
                        case 'requireField':  //考勤必填项
                            this.taskObj.require_field = data.require_field
                             // this.taskObj.require_field = value
                             // if(data.arrImg){
                             //    this.taskObj.examples_img_url = data.arrImg.img_url
                             //    this.taskObj.example_img_thumb_url = data.arrImg.img_thumb_url
                             // }else{
                             //    this.taskObj.examples_img_url = []
                             //    this.taskObj.example_img_thumb_url = []
                             // }
                            break
                        case 'noticeType':   //考勤通知
                            this.taskObj.notice_type = value
                            break
                        case 'workTimeRange':  // 考勤时间-固定时间
                            this.taskObj.work_time_range = value
                            break
                        case 'workDate': // 按天设置
                            if(data.pream && data.pream == 11){
                                this.b = true
                                this.backTime = value
                                this.taskObj.work_date_type = 0
                            }
                            break
                        case 'workWeek':
                            if(data.pream2 && data.pream2 == 22){
                                this.w = true
                                let tmp = new Array();
                                let arr = value.week
                                for(var i in arr){
                                    if(tmp.indexOf(arr[i])==-1){
                                        tmp.push(arr[i]);
                                    }
                                }
                                this.backweek = {
                                    end_date:value.end_date,
                                    start_date:value.start_date,
                                    week:tmp
                                }
                                this.taskObj.work_date_type = 1
                            }
                            break
                        case 'KaoqinAddPosition':
                            this.taskObj.position = value //获取考勤地点数量
                            if(this.taskObj.position.length == 0){
                                cache.deleteCache('KaoqinAddPosition')
                            }
                            break
                        case 'KaoqinClassesSet':
                            this.taskObj.schedule_list = value
                            //更新班次设置
                            break
                        case 'today_begin': // 
                            this.today_begin = value
                            break
                        case 'today_begin': // 
                            this.today_begin_min = value
                            break
                        default:
                            break
                    }
                }
            },
            // 验证必填项，为空时，提示
            checkDate (){
                if(!this.taskObj.name){
                    widget.toast('请输入考勤名称')
                    return false
                }
                // if(!this.taskObj.participant_group.length&&!this.taskObj.participant_user.length){
                //     widget.toast('请添加参与小组或参与人员')
                //     return false
                // }
                // if(this.taskObj.require_field.photo == 0 && this.taskObj.require_field.position == 0 && this.taskObj.require_field.remark == 0){
                //     widget.toast('请选择必填项')
                //     return false
                // }
                return true
            },
            // 编辑时页面获取借口数据
            getDate(){
                commonPage.loadPageStatus('loading')
                util.ajax({
                    url: '/attendance/attendance_task_info',
                    data: {
                        team_id:pageDate.team_id,
                        project_id: pageDate.project_id,
                        task_id:taskId
                    },
                    success: (obj) => {
                        console.log("获取考勤任务信息"+JSON.stringify(obj.data))
                        if(obj&&obj.errno==0){
                            this.taskObj = obj.data
                            
                            if(this.taskObj.require_field.length == 0){
                                this.taskObj.require_field = [
                                    {
                                        "id": '',
                                        "type": "Location",
                                        "name": "位置",
                                        "info": {
                                            "title": "位置",
                                            "value": {
                                                "lat": "",
                                                "lng": "",
                                                "addr": ""
                                            },
                                            "tune_distance":500,
                                            "tip": "",
                                            "required": 1
                                        }
                                    }
                                ]
                            }

                            if(obj.data.work_type == 0){
                                this.taskObj.work_type_info = '固定时间'
                                this.taskObj.work_time_range = obj.data.work_time_range
                            }else if(obj.data.work_type == 1){
                                this.taskObj.work_type_info = '弹性时间'
                                this.taskObj.work_time_length = obj.data.work_time_length
                                this.today_begin_min = this.taskObj.today_begin
                                let hour_data = Math.floor(this.today_begin_min/60)
                                let minute_data = this.today_begin_min%60
                                if(hour_data<10){
                                    hour_data = '0' + hour_data
                                }
                                if(minute_data<10){
                                    minute_data = '0' + minute_data
                                }
                                this.today_begin = hour_data + ':' + minute_data
                            }else if(obj.data.work_type == 2){
                                this.taskObj.work_type_info = '人员排班'
                            }
                            if(obj.data.work_date_type == 0){
                                this.taskObj.work_date_type = 0
                                this.taskObj.work_date = obj.data.work_date
                            }else if(obj.data.work_date_type == 1){
                                this.taskObj.work_date_type = 1
                                this.taskObj.work_week = obj.data.work_week
                            }
                            
                            this.doWatch()   //检测数据是否改变
                            commonPage.loadPageStatus('loadSuccess')
                        }else if(obj.errmsg){
                             widget.toast(obj.errmsg)
                             commonPage.loadPageStatus('loadSuccess')
                        }else{
                            widget.toast('数据获取失败')
                            commonPage.loadPageStatus('loadSuccess')
                        }
                    },
                    error: (xhr, status) => {
                        widget.toast('服务器异常')
                        commonPage.loadPageStatus('loadSuccess')
                    },
                    noNetwork: () => {
                        widget.toast('网络连接失败，请检查网络')
                        commonPage.loadPageStatus('loadSuccess')
                    }
                })
                
            },
            doWatch (){
                this.$watch('taskObj.name', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.participant_group_name', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.participant_user', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.position.length', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                
                this.$watch('taskObj.require_field', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.work_time_range', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.work_time_length', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })

                this.$watch('backTime', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('backweek', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.notice_type', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.examples_img_url', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.example_img_thumb_url', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                this.$watch('taskObj.adjust_distance', (newVal, oldVal) => {
                    if(newVal != oldVal){
                        this.dataChane = true
                    }else{
                        this.dataChane = false
                    }
                })
                
            },
            classesSet(){
                cache.setCache('KaoqinClassesSet',{key:'KaoqinClassesSet', value:this.taskObj.schedule_list} ,60*60*24)
                window.location.href = "dmsaas://KaoqinClassesSet"
            },
            // 弹性时间 -- 开始考勤的时间
            selectBeginTime(){
                let data = {
                    data1: []
                }
                let select = ['0']
                let time 
                                   
                for (let a = 0; a < 12 ; a++){
                    for (let b = 0; b<60; b+=30){
                        if(a<10){
                            time = '0' + a
                        }else{
                            time = a 
                        }
                        if(b==0){
                            time = time + ':' + '00'
                        }else{
                            time = time + ':' + '30'
                        }
                        b == 60 ? b=0 : b=b
                        data.data1.push(time)
                    }
                }
                data.data1.push('12:00')
                if(this.today_begin){
                    select[0]=data.data1.indexOf(this.today_begin)+''
                }
                clientUi.showPicker(data, select, '请选择时间', (returnData) => {
                    if(returnData.data1){
                        this.today_begin = data.data1[returnData.data1]
                    }else{
                        this.today_begin = this.today_begin
                    }
                    let begin_data = this.today_begin.split(':')
                    let begin_data_hour = parseInt(begin_data[0])
                    let begin_data_min = parseInt(begin_data[1])
                    this.today_begin_min = begin_data_hour*60 + begin_data_min
                    
                })
            },           
        },
        created(){
            commonPage.getWebViewID((data)=>{
                // console.log(data)
                cache.setMemoryCache('webViewID',{'webViewID':data})
            })

            this.init();
            window.loadData = this.updateDate
        },
        ready (){
            commonPage.updateTitleBar({
                backAction: 'gotoback',
                leftAction: 'gotoback',
                rightDisplay: true,
                rightText: '删除',
                rightAction: 'deleteKqrule'
            })
            //删除考勤规则
            window.deleteKqrule = () => {
                clientUi.showDialog('提示','确定删除该考勤规则？', function(data){
                    if(data.status == 1){
                        util.ajax({
                            url: '/attendance/attendance_task/delete',
                            type:'POST',
                            data: {
                                team_id:pageDate.team_id,
                                project_id: pageDate.project_id,
                                task_id:taskId
                            },
                            success: (res) => {
                                if(res&&res.errno==0){
                                    cache.deleteCache('KaoqinClassesSet')
                                    cache.deleteCache('KaoqinAddPosition')  
                                    cache.getMemoryCache('editKqViewID', (data) => {
                                        commonPage.goBack(1, {'key':'yy_kqtaskdelete'}, data.editKqViewID)
                                    })
                                }else if(res.errmsg){
                                     widget.toast(res.errmsg)
                                }else{
                                    widget.toast('删除失败')
                                }
                            },
                            error: (xhr, status) => {
                                widget.toast('服务器异常')
                            },
                            noNetwork: () => {
                                widget.toast('网络连接失败，请检查网络')
                            }
                        })
                    }
                }, '确定', '取消')
            }

            window.gotoback = () => {
                let that = this
                if(this.dataChane == true){
                    clientUi.showDialog('提醒', '内容已修改，是否保存？', function(data){
                        if(data.status == 1){
                            if(!that.checkDate()){
                                return
                            }
                            let getSubmitDate = that.getSubmitDate()
                            that.postAjax(getSubmitDate)
                        }else{
                            cache.deleteCache('KaoqinClassesSet')
                            cache.deleteCache('KaoqinAddPosition')
                            commonPage.goBack(1)
                        }
                    },'保存','不保存')
                }else{
                    cache.deleteCache('KaoqinClassesSet')
                    cache.deleteCache('KaoqinAddPosition')
                    commonPage.goBack(1)
                }
            }
            
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<style src="../../node_modules/weui/dist/style/weui.css"></style>
<style src="../../static/css/common.css"></style>
<style src="../../static/css/attendance-set.css"></style>
<style>
.placeholder{
    padding-right: 22px!important;
} 
</style>




